Arduino uploading a firmware hex file from cli command line in Linux

Based on this: https://forum.arduino.cc/index.php?topic=417659.0

Just to see what command you have to issue in order to load a hex file, you have to use your arduino IDE on a test instalation.

Just Plug in your Arduino with your USB cable, then set everything to load a script to that board. You can choose File |Examples | 01.Basics | Blink and will be just fine. Select your Arduino board from the Arduino IDE Tools | Board menu.  Then select your Arduino board’s port from the Tools | Port menu. Most likely it will be already chosen. In File | Preferences a form will appear.

About in the middle left you have a Label “Show verbose output during” and two checkboxes. “[] compilation” and  “[] upload”. Check this last one “[] upload”. When you are ready jus issue the compile and upload command on the IDE. Sketch | Upload.

In my case, with Arduino UNO, it answers with the following:

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/home/enrique/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/enrique/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:/tmp/arduino_build_260352/Blink.ino.hex:i
...

If your board is an Arduino Mega the -p parameter may read like: -patmega2560

You copy the avrdude invocation line  /home/… /bin/avrdude  and change the place of the hex file for a full path to your own hex file. And donde!

You can automate this line by making an script of the kind:

#!/bin/bash
# avrdudeload.sh
/home/.../bin/avrdude -C/home/.../etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB... -b115200 -D -Uflash:w:$1:i

Regards

Related posts